﻿#include "widget.h"
#include "ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    //图片管理
    QIcon up(":/picture/up.jpg");
    QIcon down(":/picture/down.jpg");
    QIcon left(":/picture/left.jpg");
    QIcon right(":/picture/right.jpg");
    QIcon dog(":/picture/dog.jpg");
    //将图片插入到按钮
    ui->pushButton_up->setIcon(up);
    ui->pushButton_down->setIcon(down);
    ui->pushButton_left->setIcon(left);
    ui->pushButton_right->setIcon(right);
    ui->pushButton_target->setIcon(dog);
    //设置图片大小
    ui->pushButton_up->setIconSize(ui->pushButton_up->size());
    ui->pushButton_down->setIconSize(ui->pushButton_down->size());
    ui->pushButton_left->setIconSize(ui->pushButton_left->size());
    ui->pushButton_right->setIconSize(ui->pushButton_right->size());
    ui->pushButton_target->setIconSize(ui->pushButton_target->size());
    //设置按钮快捷键
    ui->pushButton_up->setShortcut(QKeySequence("w"));
    ui->pushButton_down->setShortcut(QKeySequence("s"));
    ui->pushButton_left->setShortcut(QKeySequence("a"));
    ui->pushButton_right->setShortcut(QKeySequence("d"));
}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_pushButton_up_clicked()
{
    QRect rect = ui->pushButton_target->geometry();
    ui->pushButton_target->setGeometry(rect.x(), rect.y() - 5, rect.width(), rect.height());
}

void Widget::on_pushButton_down_clicked()
{
    QRect rect = ui->pushButton_target->geometry();
    ui->pushButton_target->setGeometry(rect.x(), rect.y() + 5, rect.width(), rect.height());
}

void Widget::on_pushButton_left_clicked()
{
    QRect rect = ui->pushButton_target->geometry();
    ui->pushButton_target->setGeometry(rect.x() - 5, rect.y(), rect.width(), rect.height());
}

void Widget::on_pushButton_right_clicked()
{
    QRect rect = ui->pushButton_target->geometry();
    ui->pushButton_target->setGeometry(rect.x() + 5, rect.y(), rect.width(), rect.height());
}

